/*
 * Copyright (c) 2015 Uwantsoft Ltd.
 * www.uwantsoft.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Uwantsoft ("Confidential Information").
 * You shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement you
 * entered into with Uwantsoft.
 */

package com.uwantsoft.interfaces.web.controller.restful;

import com.uwantsoft.business.facade.DriverFacadeImpl;
import com.uwantsoft.business.facade.dto.GuidDto;
import com.uwantsoft.business.facade.dto.address.FavoriteAddressesDto;
import com.uwantsoft.business.facade.dto.user.DriverLoginDto;
import com.uwantsoft.business.facade.dto.user.LicensePlateDto;
import com.uwantsoft.business.facade.dto.user.OrderDto;
import com.uwantsoft.business.facade.dto.user.ParkHistoryDto;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author Chuanbao
 */
@RestController
@RequestMapping("/api/v1/driver")
public class DriverController {

    @Resource(name="driverFacade")
    private DriverFacadeImpl driverFacade;

    @RequestMapping(value="/verificationcode" ,method = RequestMethod.PUT)
    public void sendVerifyCode(String mobileNumber){
        driverFacade.sendVerifyCode(mobileNumber);
    }

    @RequestMapping(value = "/login",method=RequestMethod.POST)
    public void login(@RequestBody DriverLoginDto driverLoginDto) {
        driverFacade.login(driverLoginDto);
    }

    @RequestMapping(value = "/favoriteaddresses",method = RequestMethod.POST)
    public FavoriteAddressesDto createFavoriteAddress(@RequestBody FavoriteAddressesDto favoriteAddressesDto){
        return driverFacade.createFavoriteAddress(favoriteAddressesDto);
    }

    @RequestMapping(value = "/favoriteaddresses",method = RequestMethod.GET)
    public List<FavoriteAddressesDto> obtainFavoriteAddresses(){
        return driverFacade.obtainFavoriteAddresses();
    }

    @RequestMapping(value = "/favoriteaddresses/{guid}",method = RequestMethod.DELETE)
    public void deleteFavoriteAddress(@PathVariable String guid) {
        driverFacade.deleteFavoriteAddress(guid);
    }

    @RequestMapping(value = "/licenseplates",method = RequestMethod.GET)
    public List<LicensePlateDto> obtainLicensePlates(){
        return driverFacade.obtainLicensePlates();
    }

    @RequestMapping(value = "/licenseplates",method = RequestMethod.POST)
    public LicensePlateDto createLicensePlate(@RequestBody @Valid LicensePlateDto licensePlateDto){
        return driverFacade.createLicensePlate(licensePlateDto);
    }

    @RequestMapping(value = "/prioritylicenseplate",method = RequestMethod.PUT)
    public void updatePriorityLicensePlate(@RequestBody GuidDto guidDto){
        driverFacade.updatePriorityLicensePlate(guidDto.getGuid());
    }

    @RequestMapping(value = "/licenseplates/{guid}",method = RequestMethod.DELETE)
    public void deleteLicensePlate(@PathVariable String guid){
        driverFacade.deleteLicensePlate(guid);
    }

    @RequestMapping(value = "/parkhistories",method = RequestMethod.GET)
    public List<ParkHistoryDto> obtainParkHistories(){
        return driverFacade.obtainParkHistories();
    }

    @RequestMapping(value = "/order",method = RequestMethod.GET)
    public OrderDto obtainOrder(){
        return driverFacade.obtainOrder();
    }

}
